import { Controller } from "../../mvc/core/Controller";
import { ItemData } from "../resource/info/ItemData";
import { ECategory } from "../../../Message/Public/ECategory";
import { EProp } from "../../../Message/Public/EProp";
import { EBind } from "../../../Message/Public/EBind";
import { ItemConfig } from "../resource/ItemConfig";
import { ItemInfo } from "../resource/info/ItemInfo";
import { DataEvent } from "../events/DataEvent";
import { EItemUpdateResult } from "../../../Message/Game/EItemUpdateResult";
import { EItemUpdateOper } from "../../../Message/Game/EItemUpdateOper";
import { SoundManager } from "../../common/sound/SoundManager";
import { SoundTypeConst } from "../../common/sound/SoundTypeConst";
import { IEquipModuleBase } from "../../../modules/interfaces/IEquipModuleBase";
import { NetDispatcher } from "../../mvc/core/NetDispatcher";
import { ServerCommand } from "../mvc/ServerCommand";
import { Dispatcher } from "../../mvc/core/Dispatcher";
import { EventName } from "../mvc/EventName";
import { EquipUpdateParams } from "../view/equipment/data/EquipUpdateParams";
import { GameProxy } from "../mvc/GameProxy";
import { IView } from "../../mvc/interfaces/IView";
import { WindowEvent } from "../../component/window/WindowEvent";
import { EquipmentModuleConst } from "../view/equipment/data/EquipmentModuleConst";
import { ShopItemInfo } from "../resource/info/ShopItemInfo";
import { ColorConfig } from "../resource/ColorConfig";
import { Language } from "../../../extend/language/Language";
import { HTMLUtil } from "../../../com/gengine/utils/HTMLUtil";
import { GameDefConfig } from "../resource/GameDefConfig";
import { Alert } from "../../../com/mui/controls/Alert";
import { EquipmentUtil } from "../view/common/util/EquipmentUtil";
import { SuitConfig } from "../resource/SuitConfig";
import { TItemWeapon } from "../../../Message/Db/Tables/TItemWeapon";
import { ShopType } from "../resource/info/ShopType";
import { MaterialItemData } from "../view/equipment/MaterialItemData";
import { SPlayerItem } from "../../../Message/Public/SPlayerItem";
import { _recastLockNum } from "../../../this/_recastLockNum";
import { _cost } from "../../../this/_cost";
type int = number;
//class EquipControllerBase
    
    export  class EquipControllerBase extends Controller
    {
        constructor()
        {
            
            super();this._choosedEquipmentData = [];
            this._choosedJewels = [];
            return;
        }

        protected autoSelectedRecastLocks(): void
        {
            var loc1=null;
            var loc3=0;
            var loc4=null;
            var loc7=0;
            var loc9=false;
            var loc10=null;
            var loc2=[];
            var loc5=[];
            if (this.choosedEquipmentData.length == 0) 
            {
                return;
            }
            loc1 = cache.pack.backPackCache.getPropItems();
            var loc6=[];
            loc3 = 0;
            while (loc3 < loc1.length) 
            {
                if ((loc4 = loc1[loc3] as ItemData).category == ECategory._ECategoryProp && loc4.itemInfo.item.type == EProp._EPropRefreshLock) 
                {
                    if (!(!this._useBind && loc4.bind == EBind._EBindYes)) 
                    {
                        loc6.push({"data": loc4, "bind": loc4.itemInfo.item.bind});
                    }
                }
                ++loc3;
            }
            if (this._useBind) 
            {
                loc6.sortOn("bind", Array.DESCENDING);
            }
            else 
            {
                loc6.sortOn("bind");
            }
            var loc8=[];
            loc3 = 0;
            while (loc3 < loc6.length) 
            {
                loc7 = loc7 + (loc6[loc3]["data"] as ItemData).itemAmount;
                loc8.push(loc6[loc3]["data"]);
                if (loc7 >= this._recastLockNum) 
                {
                    break;
                }
                ++loc3;
            }
            if (loc7 > 0 && loc7 >= this._recastLockNum) 
            {
                loc9 = true;
                loc2.push({"data": loc6[0]["data"], "isEnough": loc9, "amount": _recastLockNum});
            }
            else 
            {
                loc9 = false;
                loc10 = ItemConfig.instance.getPropsByType(EProp._EPropRefreshLock);
                loc3 = 0;
                while (loc3 < loc10.length) 
                {
                    if ((loc4 = new ItemData((loc10[loc3] as ItemInfo).item.code)).itemInfo.item.bind == EBind._EBindNo) 
                    {
                        break;
                    }
                    ++loc3;
                }
                loc2.push({"data": loc4, "isEnough": loc9, "amount": _recastLockNum});
            }
            _view.update({"type":"autoChooseMaterial", "material": loc2, "useLocks": loc8});
            return;
        }

        /* internal  */checkIsChoosed(arg1: ItemData): Boolean
        {
            var loc1=null;
            var loc2=0;
            loc2 = 0;
            while (loc2 < this._choosedEquipmentData.length) 
            {
                loc1 = this._choosedEquipmentData[loc2] as ItemData;
                if (loc1 && loc1.uid == arg1.uid) 
                {
                    return true;
                }
                ++loc2;
            }
            loc2 = 0;
            while (loc2 < this._choosedJewels.length) 
            {
                loc1 = this._choosedJewels[loc2] as ItemData;
                if (loc1 && loc1.uid == arg1.uid) 
                {
                    return true;
                }
                ++loc2;
            }
            return false;
        }

        protected onUpdateResult(arg1: DataEvent): void
        {
            if (_view) 
            {
                _view.update({"type":"updateResut", "resultId": arg1.data.resultId, "operation": arg1.data.operation, "autoUpdate": arg1.data.autoUpdate, "resultPlayerItem": arg1.data.resultPlayerItem, "itemUpdateResults": arg1.data.itemUpdateResults});
            }
            this.playSound(arg1.data.resultId, arg1.data.operation);
            return;
        }

        /* internal  */playSound(arg1: int, arg2: int): void
        {
            if (arg1 != EItemUpdateResult._EItemUpdateResultSuccess) 
            {
                if (arg1 == EItemUpdateResult._EItemUpdateResultFail) 
                {
                    loc1 = arg2;
                    switch (loc1) 
                    {
                        case EItemUpdateOper._EItemUpdateJewelAddance: case EItemUpdateOper._EItemUpdateOperEmbedJewel: case EItemUpdateOper._EItemUpdateOperRemoveJewel:
                        {
                            SoundManager.instance.soundPlay(SoundTypeConst.JewelsUpdateFailed);
                            break;
                        }
                        case EItemUpdateOper._EItemUpdateComposeJewel:
                        {
                            SoundManager.instance.soundPlay(SoundTypeConst.JewelsSynthesisFailure);
                            break;
                        }
                        default:
                        {
                            SoundManager.instance.soundPlay(SoundTypeConst.JewelsUpdateFailed);
                            break;
                        }
                    }
                }
            }
            else 
            {
                var loc1=arg2;
                switch (loc1) 
                {
                    case EItemUpdateOper._EItemUpdateComposeJewel:
                    {
                        SoundManager.instance.soundPlay(SoundTypeConst.JewelsSynthesisSuccess);
                        break;
                    }
                    case EItemUpdateOper._EItemUpdateOperRemoveJewel:
                    {
                        SoundManager.instance.soundPlay(SoundTypeConst.JewelsExtraction);
                        break;
                    }
                    case EItemUpdateOper._EItemUpdateOperEmbedJewel:
                    {
                        SoundManager.instance.soundPlay(SoundTypeConst.JewelsSet);
                        break;
                    }
                    case EItemUpdateOper._EItemUpdateJewelAddance:
                    {
                        SoundManager.instance.soundPlay(SoundTypeConst.JewelsQuenching);
                        break;
                    }
                    case EItemUpdateOper._EItemUpdateOperMakeHole:
                    {
                        SoundManager.instance.soundPlay(SoundTypeConst.EquipmentPunching);
                        break;
                    }
                    case EItemUpdateOper._EItemUpdatePetEquipUpgradeStar:
                    {
                        SoundManager.instance.soundPlay(SoundTypeConst.EquidAdvanted);
                        break;
                    }
                    case EItemUpdateOper._EItemUpdatePetEquipRecast:
                    {
                        SoundManager.instance.soundPlay(SoundTypeConst.EquidReset);
                        break;
                    }
                    case EItemUpdateOper._EItemUpdateOperRecast:
                    {
                        SoundManager.instance.soundPlay(SoundTypeConst.WashingEquipment);
                        break;
                    }
                    case EItemUpdateOper._EItemUpdateOperAdvance:
                    {
                        SoundManager.instance.soundPlay(SoundTypeConst.EquippedAdvanced);
                        break;
                    }
                    case EItemUpdateOper._EItemUpdateDecompose:
                    {
                        SoundManager.instance.soundPlay(SoundTypeConst.EquipmentDecomposition);
                        break;
                    }
                    case EItemUpdateOper._EItemUpdateUpdradePrefix:
                    {
                        SoundManager.instance.soundPlay(SoundTypeConst.EquipmentQuality);
                        break;
                    }
                    case EItemUpdateOper._EItemUpdateStrengthenShift:
                    {
                        SoundManager.instance.soundPlay(SoundTypeConst.EnhancedTransfer);
                        break;
                    }
                    case EItemUpdateOper._EItemUpdateOperAdvanceColor:
                    {
                        SoundManager.instance.soundPlay(SoundTypeConst.EquippedJingLian);
                        break;
                    }
                    case EItemUpdateOper._EItemUpdatePetEquipUpgradePrefix:
                    {
                        SoundManager.instance.soundPlay(SoundTypeConst.PetEquipmentQuality);
                        break;
                    }
                    case EItemUpdateOper._EItemUpdateOperEquipSmelt:
                    {
                        SoundManager.instance.soundPlay(SoundTypeConst.EquipmentRongL);
                        break;
                    }
                    case EItemUpdateOper._EItemUpdateOperMerge:
                    {
                        SoundManager.instance.soundPlay(SoundTypeConst.EquipmentRongH);
                        break;
                    }
                    case EItemUpdateOper._EItemUpdateOperStrengthen:
                    {
                        break;
                    }
                    default:
                    {
                        SoundManager.instance.soundPlay(SoundTypeConst.EquipmentsUpdateSuccess);
                        break;
                    }
                }
            }
            return;
        }

        /* internal  */onOpenDocastPanel(arg1: DataEvent): void
        {
            var loc1=arg1.data as int;
            if ((view as IEquipModuleBase).checkHasOperType(loc1)) 
            {
                view.show();
                this.showToPanel(loc1);
            }
            return;
        }

        protected /* override */ initServer(): void
        {
            NetDispatcher.addCmdListener(ServerCommand.MoneyUpdate, this.updateCost);
            NetDispatcher.addCmdListener(ServerCommand.BackpackDataChange, this.serverBagDataChangehandler);
            NetDispatcher.addCmdListener(ServerCommand.BackPackItemsChange, this.serverBagDataChangehandler);
            NetDispatcher.addCmdListener(ServerCommand.RolePackItemsChange, this.serverBagDataChangehandler);
            NetDispatcher.addCmdListener(ServerCommand.BackPackWardrobeItemsChange, this.serverBagDataChangehandler);
            NetDispatcher.addCmdListener(ServerCommand.StonepackItemsChange, this.stoneBagDataChangehandler);
            NetDispatcher.addCmdListener(ServerCommand.StonepackDataChange, this.stoneBagDataChangehandler);
            Dispatcher.addEventListener(EventName.Equipment_DoCast, this.onOpenDocastPanel);
            Dispatcher.addEventListener(EventName.Equipment_UpdateResult, this.onUpdateResult);
            Dispatcher.addEventListener(EventName.Equipment_UpdateError, this.onUpdateError);
            Dispatcher.addEventListener(EventName.Equipment_OnAutoBuyChange, this.onAutoBuyChange);
            Dispatcher.addEventListener(EventName.Equipment_OnBuyDirectChange, this.onBuyDirectChange);
            return;
        }

        /* internal  */onAutoBuyChange(arg1: DataEvent): void
        {
            cache.equipment.isAutoBuy = arg1.data;
            if (_view) 
            {
                _view.update({"type":"setAutoBuy", "data": arg1.data});
            }
            return;
        }

        /* internal  */onBuyDirectChange(arg1: DataEvent): void
        {
            cache.equipment.isBuyDirectly = arg1.data;
            if (_view) 
            {
                _view.update({"type":"setBuyDirect", "data": arg1.data});
            }
            return;
        }

        protected doUpdate(arg1: DataEvent): void
        {
            var loc2=0;
            this._choosedMaterial = [];
            var loc1=arg1.data as EquipUpdateParams;
            if (loc1.operationId == EItemUpdateOper._EItemUpdateOperStrengthen || loc1.operationId == EItemUpdateOper._EItemUpdateOperPetEquipStrengthen) 
            {
                if (cache.guide.guideEquipRefresh && cache.guide.guideEquipRefreshCount <= 3) 
                {
                    GameProxy.guideProxy.weaponStrengthenTask(loc1.equipPosType, loc1.equipUid, loc1.autoUpdate);
                }
                else 
                {
                    GameProxy.equipmentProxy.equipUpdate(loc1.operationId, loc1.equipPosType, loc1.equipUid, loc1.materials, loc1.autoUpdate, loc1.flag, false, loc1.target, loc1.autoBuyTone);
                }
            }
            else if (loc1.operationId == EItemUpdateOper._EItemUpdateOperRefine || loc1.operationId == EItemUpdateOper._EItemUpdateOperAdvance || loc1.operationId == EItemUpdateOper._EItemUpdateOperAdvanceColor) 
            {
                GameProxy.equipmentProxy.equipUpdate(loc1.operationId, loc1.equipPosType, loc1.equipUid, loc1.materials, loc1.autoUpdate, loc1.flag, false, loc1.target, loc1.autoBuyTone);
            }
            else if (loc1.operationId == EItemUpdateOper._EItemUpdateOperRecast || loc1.operationId == EItemUpdateOper._EItemUpdatePetEquipRefresh) 
            {
                GameProxy.equipmentProxy.equipRefresh(loc1.equipPosType, loc1.equipUid, "", loc1.operType, loc1.flag, loc1.lockPos, loc1.materials, loc1.refreshNumType, loc1.expectAttr, loc1.replaceIndex, loc1.expectAttrAll, loc1.autoBuyTone, loc1.autoBuyLock);
            }
            else if (loc1.operationId != EItemUpdateOper._EItemUpdateDecompose) 
            {
                if (loc1.operationId != EItemUpdateOper._EItemUpdateRefreshPropCompose) 
                {
                    if (loc1.operationId != EItemUpdateOper._EItemUpdateUpdradePrefix) 
                    {
                        if (loc1.operationId != EItemUpdateOper._EItemUpdateStrengthenShift) 
                        {
                            if (loc1.operationId != EItemUpdateOper._EItemUpdateOperEquipSmelt) 
                            {
                                if (loc1.operationId != EItemUpdateOper._EItemUpdatePetEquipUpgradeStar) 
                                {
                                    if (loc1.operationId != EItemUpdateOper._EItemUpdatePetEquipRecast) 
                                    {
                                        if (loc1.operationId == EItemUpdateOper._EItemUpdatePetEquipUpgradePrefix || loc1.operationId == EItemUpdateOper._EItemUpdatePetEquipTransform) 
                                        {
                                            GameProxy.petEquip.petEquipUpgrade(loc1.operationId, loc1.equipPosType, loc1.equipUid, loc1.target, loc1.materials, loc1.equipUidArr);
                                        }
                                        else if (loc1.operationId != EItemUpdateOper._EItemUpdateOperPetEquipAdvance) 
                                        {
                                            loc2 = loc1.flag ? 1 : 0;
                                            GameProxy.equipmentProxy.itemUpdate_async(loc1.operationId, loc1.autoUpdate, loc1.equipPosType, loc1.materials, loc1.target, loc1.num, loc2, loc1.autoBuyTone);
                                        }
                                        else 
                                        {
                                            GameProxy.petEquip.petEquipAdvance(loc1.equipUid, loc1.equipUid2, loc1.materials, loc1.flag);
                                        }
                                    }
                                    else 
                                    {
                                        GameProxy.petEquip.petEquipRecast(loc1.equipPosType, loc1.equipUid, loc1.materialUid, loc1.itemColor);
                                    }
                                }
                                else 
                                {
                                    GameProxy.petEquip.petEquipStarUpgrade(loc1.equipPosType, loc1.equipUid, loc1.materials);
                                }
                            }
                            else 
                            {
                                GameProxy.equipmentProxy.equipMelt(loc1.equipUid, loc1.equipUid2, loc1.materials, loc1.autoBuyTone);
                            }
                        }
                        else 
                        {
                            GameProxy.equipmentProxy.equipStrengthenShift(loc1.equipPosType, loc1.equipPosType2, loc1.equipUid, loc1.equipUid2);
                        }
                    }
                    else 
                    {
                        GameProxy.equipmentProxy.equipUpgradePrefix(loc1.equipPosType, loc1.equipUid, loc1.materials);
                    }
                }
                else 
                {
                    GameProxy.equipmentProxy.propRefreshCompose(loc1.materialUidDic, loc1.target);
                }
            }
            else 
            {
                GameProxy.equipmentProxy.equipDecompose(loc1.equipUidDic, loc1.materialUid);
            }
            return;
        }

        protected doCastHandler(arg1: DataEvent): void
        {
            return;
        }

        public get choosedEquipmentData(): Array<any>
        {
            return this._choosedEquipmentData;
        }

        protected showToPanel(arg1: int=0): void
        {
            _view.update({"type":"showToPanel", "data": arg1});
            return;
        }

        protected addCommonListeners(arg1: IView): void
        {
            arg1.addEventListener(WindowEvent.SHOW, this.onShowHandler);
            arg1.addEventListener(WindowEvent.CLOSE, this.onClose);
            arg1.addEventListener(EquipmentModuleConst.Event_OpertionTypeChange, this.opertionTypeChangeHandler);
            arg1.addEventListener(EquipmentModuleConst.Event_EquipmentTypeChange, this.equipmentTypeChangeHandler);
            arg1.addEventListener(EquipmentModuleConst.Event_MaterialTypeChange, this.materialTypeChangeHandler);
            arg1.addEventListener(EquipmentModuleConst.Event_ChoosedEquimentChange, this.choosedEquimentChangeHandler);
            arg1.addEventListener(EquipmentModuleConst.Event_ChoosedMaterialChange, this.choosedMaterialChangeHandler);
            arg1.addEventListener(EquipmentModuleConst.Event_DoBuyEvent, this.buyMaterialHandler);
            arg1.addEventListener(EquipmentModuleConst.Event_UseBindChange, this.useBindChangeHandler);
            arg1.addEventListener(EquipmentModuleConst.Event_CostChange, this.costChangeHandler);
            arg1.addEventListener(EquipmentModuleConst.Event_DoUpdateEvent1, this.doUpdate);
            arg1.addEventListener(EquipmentModuleConst.Event_LuckTuneNumChange, this.LuckTuneNumChangeHandler);
            arg1.addEventListener(EquipmentModuleConst.Event_AddHintLabel, this.doAddHintLabel);
            arg1.addEventListener(EquipmentModuleConst.Event_DoUpdateEquipment, this.doUpdateEquipment);
            arg1.addEventListener(EquipmentModuleConst.Event_CoinNotEnough, this.onCoinNotEnough);
            arg1.addEventListener(EquipmentModuleConst.Event_ChangeMaterialTabBarIndex, this.doChangeMaterialTab);
            arg1.addEventListener(EquipmentModuleConst.Event_RecastLockNumChange, this.onRecastLockNumChange);
            return;
        }

        protected serverBagDataChangehandler(arg1: Object=null): void
        {
            if (_view && !_view.isHide) 
            {
                this.updateEquipment();
                this.doUpdateMaterial();
                this.checkEquipLost();
                this.autoSelectedMaterial();
            }
            return;
        }

        protected stoneBagDataChangehandler(arg1: Object=null): void
        {
            this.serverBagDataChangehandler(arg1);
            return;
        }

        /* internal  */opertionTypeChangeHandler(arg1: DataEvent): void
        {
            this._opertionType = Number(arg1.data);
            this._choosedEquipmentData = [];
            this._choosedJewels = [];
            this._choosedMaterial = [];
            this._cost = 0;
            this.updateEquipment();
            this.updateCost();
            this.doUpdateMaterial();
            return;
        }

        /* internal  */buyMaterialHandler(arg1: DataEvent): void
        {
            var loc1=null;
            var loc2=0;
            var loc3=0;
            var loc4=null;
            var loc5=null;
            if (cache.equipment.isBuyDirectly) 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.ShopMallBuyItem, arg1.data));
            }
            else 
            {
                loc1 = arg1.data.shopItemInfo as ShopItemInfo;
                loc2 = arg1.data.amount as int;
                loc3 = loc1.tshopSell.offer > 0 ? loc1.tshopSell.offer * loc2 : loc1.tshopSell.price * loc2;
                loc4 = ColorConfig.instance.getItemColor(loc1.itemInfo.item.color);
                loc5 = "        " + Language.getStringByParam(61023, HTMLUtil.addColor(loc2 + "", "#FF0000"), HTMLUtil.addColor(loc1.itemInfo.item.name, loc4.color), HTMLUtil.addColor(loc3 + GameDefConfig.instance.getEPrictUnitName(loc1.unit), "#FFEA00"));
                Alert.extendObj = arg1.data;
                Alert.show(loc5, Language.getString(69900), Alert.OK | Alert.CANCEL, null, this.onBuyAlertHanlder);
            }
            return;
        }

        /* internal  */onBuyAlertHanlder(arg1: int, arg2: Object): void
        {
            if (arg1 == Alert.OK) 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.ShopMallBuyItem, arg2));
            }
            return;
        }

        /* internal  */costChangeHandler(arg1: DataEvent): void
        {
            this._cost = Number(arg1.data);
            this.updateCost();
            return;
        }

        protected useBindChangeHandler(arg1: DataEvent): void
        {
            this._useBind = Boolean(arg1.data);
            this.autoSelectedMaterial();
            return;
        }

        /* internal  */equipmentTypeChangeHandler(arg1: DataEvent): void
        {
            this._equipmentType = Number(arg1.data);
            this.updateEquipment();
            return;
        }

        /* internal  */materialTypeChangeHandler(arg1: DataEvent): void
        {
            if (arg1.data != null) 
            {
                this._materialType = Number(arg1.data);
            }
            this.doUpdateMaterial();
            return;
        }

        protected choosedMaterialChangeHandler(arg1: DataEvent): void
        {
            this._choosedMaterial = arg1.data as Array<any>;
            this.autoSelectedMaterial();
            return;
        }

        /* internal  */choosedEquimentChangeHandler(arg1: DataEvent): void
        {
            this._choosedEquipmentData = arg1.data as Array<any>;
            this.updateEquipment();
            this.autoSelectedMaterial();
            return;
        }

        /* internal  */LuckTuneNumChangeHandler(arg1: DataEvent): void
        {
            this._useLuckTuneNum = Number(arg1.data);
            this.autoSelectedMaterial();
            return;
        }

        protected onShowHandler(arg1: Object /* flash.events.Event */): void
        {
            this.updateCost();
            this.updateEquipment();
            this.doUpdateMaterial();
            this.autoSelectedMaterial();
            return;
        }

        protected onClose(arg1: Object /* flash.events.Event */): void
        {
            return;
        }

        protected updateEquipment(): void
        {
            var loc1=0;
            var loc3=null;
            var loc4=null;
            var loc5=null;
            var loc6=null;
            var loc2=[];
            if (this._opertionType == EItemUpdateOper._EItemUpdateComposeJewel || this._opertionType == EItemUpdateOper._EItemUpdateJewelAddance) 
            {
                loc2 = cache.equipment.getJewelData(this._opertionType, this._equipmentType, null);
            }
            else if (this._equipmentType != EquipmentModuleConst.EquipmentType_RefreshProp) 
            {
                if (EquipmentUtil.isPetEquipUpdateOper(this._opertionType)) 
                {
                    loc2 = cache.equipment.getPetEquipmentData(this._opertionType, this._equipmentType);
                }
                else 
                {
                    loc2 = cache.equipment.getEquipmentData(this._opertionType, this._equipmentType);
                }
            }
            else 
            {
                loc2 = cache.equipment.getMaterialData(this._opertionType);
            }
            if (this._opertionType == EItemUpdateOper._EItemUpdateStrengthenShift) 
            {
                this.filterStrengthenShiftEquip(loc2);
            }
            if (this._choosedEquipmentData.length > 0 || this._choosedJewels.length > 0) 
            {
                loc1 = 0;
                while (loc1 < loc2.length) 
                {
                    if (this.checkIsChoosed(loc2[loc1].data)) 
                    {
                        loc2[loc1].used = true;
                    }
                    else 
                    {
                        loc2[loc1].used = false;
                    }
                    ++loc1;
                }
            }
            if (cache.guide.guideEquipRefresh && this._opertionType == EItemUpdateOper._EItemUpdateOperStrengthen) 
            {
                loc3 = cache.equipment.getStrengthenGuideEquip();
                if (loc3) 
                {
                    loc1 = 0;
                    while (loc1 < loc2.length) 
                    {
                        if ((loc5 = loc2[loc1]["data"] as ItemData).uid == loc3.uid) 
                        {
                            loc6 = loc2.splice(loc1, 1);
                            loc2.unshift(loc6[0]);
                        }
                        ++loc1;
                    }
                }
            }
            _view.update({"type":"updateEquipment", "data": loc2});
            return;
        }

        /* internal  */filterStrengthenShiftEquip(arg1: Array<any>): void
        {
            var loc1=0;
            var loc2=null;
            var loc3=null;
            var loc4=null;
            var loc5=null;
            if (this._choosedEquipmentData.length > 0) 
            {
                loc3 = this._choosedEquipmentData[0] as ItemData;
            }
            loc1 = (arg1.length - 1);
            while (loc1 >= 0) 
            {
                loc2 = arg1[loc1]["data"] as ItemData;
                if (loc3) 
                {
                    if (!(loc2.itemInfo.item.type == loc3.itemInfo.item.type) || !(loc2.itemInfo.item.career == loc3.itemInfo.item.career) || loc2.itemExInfo.strengthen >= loc3.itemExInfo.strengthen) 
                    {
                        arg1.splice(loc1, 1);
                    }
                    else if (loc2.color < loc3.color) 
                    {
                        arg1.splice(loc1, 1);
                    }
                    else if (loc2.color == loc3.color && loc2.itemInfo.item.level < loc3.itemInfo.item.level) 
                    {
                        arg1.splice(loc1, 1);
                    }
                    else if (loc2.color == loc3.color && loc2.itemInfo.item.level == loc3.itemInfo.item.level) 
                    {
                        loc4 = SuitConfig.instance.getInfoByCode((loc3.itemInfo.extend as TItemWeapon).suit);
                        loc5 = SuitConfig.instance.getInfoByCode((loc2.itemInfo.extend as TItemWeapon).suit);
                        if (!(loc4 == null) && loc5 == null) 
                        {
                            arg1.splice(loc1, 1);
                        }
                        else if (!(loc4 == null) && !(loc5 == null) && loc5.suitLevel < loc4.suitLevel) 
                        {
                            arg1.splice(loc1, 1);
                        }
                    }
                }
                else if (loc2.itemExInfo.strengthen < 1) 
                {
                    arg1.splice(loc1, 1);
                }
                --loc1;
            }
            return;
        }

        /* internal  */filterEquipMeltEquip(arg1: Array<any>): void
        {
            var loc1=0;
            var loc2=null;
            var loc3=null;
            if (this._choosedEquipmentData.length > 0) 
            {
                loc2 = this._choosedEquipmentData[0] as ItemData;
                loc1 = (arg1.length - 1);
                while (loc1 >= 0) 
                {
                    loc3 = arg1[loc1]["data"] as ItemData;
                    if (!(loc2.itemInfo.item.type == loc3.itemInfo.item.type) || !(loc2.itemInfo.item.career == loc3.itemInfo.item.career)) 
                    {
                        arg1.splice(loc1, 1);
                    }
                    --loc1;
                }
            }
            return;
        }

        protected checkEquipLost(): void
        {
            var loc1=false;
            var loc3=null;
            var loc4=null;
            var loc5=null;
            var loc6=null;
            var loc7=null;
            var loc8=null;
            var loc9=null;
            var loc10=null;
            var loc11=0;
            var loc12=0;
            var loc2=this._choosedEquipmentData.concat(this._choosedJewels);
            if (loc2.length > 0) 
            {
                loc3 = [];
                loc4 = [];
                loc5 = [];
                loc6 = [];
                loc7 = cache.pack.backPackCache.getEquipItems();
                if (this._opertionType != EItemUpdateOper._EItemUpdateDecompose) 
                {
                    loc3 = cache.pack.rolePackCache.getEquipItems();
                    loc4 = cache.pack.petEquip.getAllEquips();
                    loc5 = cache.pack.wardrobePackCache.getEquipItems();
                }
                if (this._opertionType == EItemUpdateOper._EItemUpdateJewelAddance) 
                {
                    loc6 = cache.pack.stonePackCache.getJewelItems();
                }
                loc8 = loc7.concat(loc3, loc4, loc5, loc6);
                loc9 = [];
                loc11 = 0;
                while (loc11 < loc2.length) 
                {
                    loc1 = false;
                    loc10 = loc2[loc11] as ItemData;
                    loc12 = 0;
                    while (loc12 < loc8.length) 
                    {
                        if (loc10.category == ECategory._ECategoryJewel && !(loc10.uid.indexOf((loc8[loc12] as ItemData).uid) == -1) && loc10.posType == (loc8[loc12] as ItemData).posType) 
                        {
                            loc1 = true;
                            break;
                        }
                        else if (loc10.uid == (loc8[loc12] as ItemData).uid && loc10.posType == (loc8[loc12] as ItemData).posType && loc10.itemExInfo.hole1 == (loc8[loc12] as ItemData).itemExInfo.hole1 && loc10.itemExInfo.hole2 == (loc8[loc12] as ItemData).itemExInfo.hole2 && loc10.itemExInfo.hole3 == (loc8[loc12] as ItemData).itemExInfo.hole3 && loc10.itemExInfo.hole4 == (loc8[loc12] as ItemData).itemExInfo.hole4 && loc10.itemExInfo.hole5 == (loc8[loc12] as ItemData).itemExInfo.hole5 && loc10.itemExInfo.hole6 == (loc8[loc12] as ItemData).itemExInfo.hole6 && loc10.itemExInfo.strengthen == (loc8[loc12] as ItemData).itemExInfo.strengthen) 
                        {
                            loc1 = true;
                            break;
                        }
                        ++loc12;
                    }
                    if (!loc1) 
                    {
                        loc9.push(loc10);
                    }
                    ++loc11;
                }
                if (loc9.length > 0) 
                {
                    _view.update({"type":"equipmentLost", "data": loc9});
                }
            }
            return;
        }

        /* internal  */doUpdateMaterial(): void
        {
            if (this._materialType != EquipmentModuleConst.MaterialType_Use) 
            {
                if (this._materialType == EquipmentModuleConst.MaterialType_Jewel) 
                {
                    this.updateMaterialJewel();
                }
            }
            else 
            {
                this.updateMaterial();
            }
            return;
        }

        /* internal  */updateMaterial(): void
        {
            var loc3=null;
            var loc4=null;
            var loc6=0;
            var loc7=0;
            var loc8=null;
            var loc9=null;
            var loc10=0;
            var loc11=null;
            var loc12=null;
            var loc13=null;
            var loc1=[];
            var loc2=new Map<any, any> /* flash.utils.Dictionary */();
            loc3 = cache.equipment.getMaterialData(this._opertionType);
            var loc5=ShopType.Equipment;
            loc4 = cache.equipment.getMaterialBuyData(this._opertionType, loc5);
            if (EquipmentUtil.isPetEquipUpdateOper(this._opertionType)) 
            {
                loc5 = ShopType.PetForge;
                loc13 = cache.equipment.getMaterialBuyData(this._opertionType, loc5);
                loc4 = loc4.concat(loc13);
            }
            loc6 = 0;
            while (loc6 < loc3.length) 
            {
                if ((loc9 = loc3[loc6]["data"] as ItemData).itemInfo.item.bind != EBind._EBindYes) 
                {
                    loc10 = loc9.itemInfo.item.code;
                }
                else 
                {
                    loc10 = loc9.itemInfo.item.codeUnbind;
                }
                if (loc10 != 0) 
                {
                    if (loc2[loc10]) 
                    {
                        (loc2[loc10] as MaterialItemData).itemData.itemAmount = (loc2[loc10] as MaterialItemData).itemData.itemAmount + loc9.itemAmount;
                    }
                    else 
                    {
                        (loc8 = new MaterialItemData()).itemData = new ItemData(loc10);
                        loc8.itemData.itemAmount = loc9.itemAmount;
                        loc8.itemData.uid = loc9.uid;
                        loc2[loc10] = loc8;
                    }
                }
                ++loc6;
            }
            loc6 = 0;
            while (loc6 < loc4.length) 
            {
                loc12 = loc4[loc6]["data"];
                if (loc2[loc12.itemInfo.item.code]) 
                {
                    (loc8 = loc2[loc12.itemInfo.item.code] as MaterialItemData).isInShop = true;
                    loc8.shopItem = loc12;
                }
                else 
                {
                    (loc8 = new MaterialItemData()).isInShop = true;
                    loc8.shopItem = loc12;
                    (loc11 = new SPlayerItem()).itemCode = loc12.itemInfo.item.code;
                    loc8.itemData = new ItemData(loc11);
                    loc2[loc11.itemCode] = loc8;
                }
                ++loc6;
            }
            var loc14=0;
            var loc15=loc2;
            for(loc8 of loc15) 
            {
                loc1.push(loc8);
            }
            loc1.sortOn("code");
            _view.update({"type":"updateMaterial", "data": loc1});
            return;
        }

        /* internal  */updateMaterialJewel(): void
        {
            var loc1=null;
            if (this._choosedEquipmentData.length > 0 && this._choosedEquipmentData[0] is ItemData) 
            {
                loc1 = this._choosedEquipmentData[0] as ItemData;
            }
            var loc2=cache.equipment.getJewelData(this._opertionType, EquipmentModuleConst.EquipmentType_Stone, loc1);
            loc2.sortOn("code");
            _view.update({"type":"updateMaterial", "data": loc2});
            return;
        }

        protected updateCost(arg1: Object=null): void
        {
            if (_view && !_view.isHide) 
            {
                _view.update({"type":"updateCost", "data":{"moneyHave": cache.role.money.coinBind + cache.role.money.coin, "cost": _cost, "gold": cache.role.money.gold, "coin": cache.role.money.coin, "coinBind": cache.role.money.coinBind}});
            }
            return;
        }

        /* internal  */doAddHintLabel(arg1: DataEvent): void
        {
            var loc1=arg1.data as string;
            (view as IEquipModuleBase).addHintLabel(loc1);
            return;
        }

        /* internal  */doUpdateEquipment(arg1: DataEvent): void
        {
            this.updateEquipment();
            return;
        }

        /* internal  */onCoinNotEnough(arg1: DataEvent): void
        {
            var loc1=cache.role.money.coinBind + cache.role.money.coin;
            if (this._cost > loc1) 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.ShopMallAutoBuyCoin, this._cost - loc1));
            }
            return;
        }

        /* internal  */doChangeMaterialTab(arg1: DataEvent): void
        {
            var loc1=arg1.data as int;
            (view as IEquipModuleBase).setMaterialTabBarIndex(loc1);
            return;
        }

        protected autoSelectedMaterial(): void
        {
            return;
        }

        /* internal  */onUpdateError(arg1: DataEvent): void
        {
            if (_view) 
            {
                _view.update({"type":"updateError"});
            }
            return;
        }

        /* internal  */onRecastLockNumChange(arg1: DataEvent): void
        {
            this._recastLockNum = arg1.data as int;
            this.autoSelectedRecastLocks();
            return;
        }

        protected /* var */_opertionType: int=0;

        protected /* var */_equipmentType: int=-1;

        protected /* var */_materialType: int=0;

        protected /* var */_cost: int=0;

        protected /* var */_successRate: int=0;

        protected /* var */_choosedJewels: Array<any>;

        protected /* var */_choosedMaterial: Array<any>;

        protected /* var */_useBind: Boolean=true;

        protected /* var */_useLuckTuneNum: int=0;

        protected /* var */_choosedEquipmentData: Array<any>;

        private /* var */_recastLockNum: int=0;
    }
